import 'package:getx_demo/common/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'index.dart';

final double margin = 32.w;

class ForgetsendsmsPage extends GetView<ForgetsendsmsController> {
  const ForgetsendsmsPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return KeyboardDismissOnTap(
      dismissOnCapturedTaps: true,
      child: Column(
        children: [
          SizedBox(height: 27.h),
          _buildCode(),
          SizedBox(height: 22.h),
          _buildPwd(),
          SizedBox(height: 22.h),
          _buildPwdAgain(),
          SizedBox(height: 40.h),
          _buildNext(),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ForgetsendsmsController>(
      init: ForgetsendsmsController(),
      id: "forgetsendsms",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("忘记密码")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }

  Container _buildCode() {
    return Container(
      margin: EdgeInsets.only(left: margin, right: margin),
      decoration: BoxDecoration(
        //设置四周圆角 角度
        borderRadius: const BorderRadius.all(Radius.circular(4.0)),
        //设置四周边框
        border: Border.all(width: 0.5, color: '#97A1B0'.toColor()),
        color: Colors.white,
      ),
      child: SizedBox(
        height: 45,
        child: Row(
          children: [
            Expanded(
              child: TextField(
                textAlign: TextAlign.left,
                // controller: _codeController,
                keyboardType: TextInputType.text,
                autofocus: true,
                textInputAction: TextInputAction.done,
                style: const TextStyle(color: Colors.black, fontSize: 14),
                decoration: InputDecoration(
                  contentPadding: const EdgeInsets.only(left: 13.5),
                  hintText: "请输入短信验证码",
                  border: InputBorder.none,
                  hintStyle:
                      TextStyle(color: '#B6B6B6'.toColor(), fontSize: 14),
                ),
              ),
            ),
            SizedBox(
              width: 100,
              child: TextButton(
                onPressed: controller.sendSMS,
                // onPressed: () {},
                child: Text(
                  // '发送验证码',
                  // '1'
                  // style: inkWellStyle,
                  controller.verifyStr,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Container _buildPwd() {
    return Container(
      margin: EdgeInsets.only(left: margin, right: margin),
      decoration: BoxDecoration(
        //设置四周圆角 角度
        borderRadius: const BorderRadius.all(Radius.circular(4.0)),
        //设置四周边框
        border: Border.all(width: 0.5, color: '#97A1B0'.toColor()),
        color: Colors.white,
      ),
      child: SizedBox(
        height: 45,
        child: TextField(
          obscureText: true,
          textAlign: TextAlign.left,
          // controller: _pwdController,
          keyboardType: TextInputType.text,
          autofocus: true,
          textInputAction: TextInputAction.done,
          style: const TextStyle(color: Colors.black, fontSize: 14),
          decoration: InputDecoration(
            contentPadding: const EdgeInsets.only(left: 13.5),
            hintText: "请输入密码",
            border: InputBorder.none,
            hintStyle: TextStyle(color: '#B6B6B6'.toColor(), fontSize: 14),
          ),
        ),
      ),
    );
  }

  Container _buildPwdAgain() {
    return Container(
      margin: EdgeInsets.only(left: margin, right: margin),
      decoration: BoxDecoration(
        //设置四周圆角 角度
        borderRadius: const BorderRadius.all(Radius.circular(4.0)),
        //设置四周边框
        border: Border.all(width: 0.5, color: '#97A1B0'.toColor()),
        color: Colors.white,
      ),
      child: SizedBox(
        height: 45,
        child: TextField(
          obscureText: true,
          textAlign: TextAlign.left,
          // controller: _pwdAgainController,
          keyboardType: TextInputType.text,
          autofocus: true,
          textInputAction: TextInputAction.done,
          style: const TextStyle(color: Colors.black, fontSize: 14),
          decoration: InputDecoration(
            contentPadding: const EdgeInsets.only(left: 13.5),
            hintText: "请再次输入密码",
            border: InputBorder.none,
            hintStyle: TextStyle(color: '#B6B6B6'.toColor(), fontSize: 14),
          ),
        ),
      ),
    );
  }

  Widget _buildNext() {
    return SizedBox(
      width: ScreenUtil().screenWidth - margin * 2,
      height: 44,
      child: ElevatedButton(
        onPressed: () {
          // _doNext();
        },
        style: ButtonStyle(
          shape: MaterialStateProperty.all(
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(22))),
          overlayColor: MaterialStateProperty.resolveWith((states) {
            return Colors.transparent;
          }),
          elevation: MaterialStateProperty.all(0),
          backgroundColor: MaterialStateProperty.all('#0E67E7'.toColor()),
        ),
        child: const Text(
          '完成',
          style: TextStyle(fontSize: 18),
        ),
      ),
    );
  }
}
